.class public Lnet/oauth/signature/pem/PEMReader;
.super Ljava/lang/Object;
.source "PEMReader.java"


# static fields
.field private static final BEGIN_MARKER:Ljava/lang/String; = "-----BEGIN "

.field public static final CERTIFICATE_X509_MARKER:Ljava/lang/String; = "-----BEGIN CERTIFICATE-----"

.field public static final PRIVATE_PKCS1_MARKER:Ljava/lang/String; = "-----BEGIN RSA PRIVATE KEY-----"

.field public static final PRIVATE_PKCS8_MARKER:Ljava/lang/String; = "-----BEGIN PRIVATE KEY-----"

.field public static final PUBLIC_X509_MARKER:Ljava/lang/String; = "-----BEGIN PUBLIC KEY-----"


# instance fields
.field private beginMarker:Ljava/lang/String;

.field private derBytes:[B

.field private stream:Ljava/io/InputStream;


# direct methods
.method public constructor <init>(Ljava/io/InputStream;)V
    .locals 0
    .parameter "inStream"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 60
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 61
    iput-object p1, p0, Lnet/oauth/signature/pem/PEMReader;->stream:Ljava/io/InputStream;

    .line 62
    invoke-virtual {p0}, Lnet/oauth/signature/pem/PEMReader;->readFile()V

    .line 63
    return-void
.end method

.method public constructor <init>(Ljava/lang/String;)V
    .locals 1
    .parameter "fileName"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 70
    new-instance v0, Ljava/io/FileInputStream;

    invoke-direct {v0, p1}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V

    invoke-direct {p0, v0}, Lnet/oauth/signature/pem/PEMReader;-><init>(Ljava/io/InputStream;)V

    .line 71
    return-void
.end method

.method public constructor <init>([B)V
    .locals 1
    .parameter "buffer"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 66
    new-instance v0, Ljava/io/ByteArrayInputStream;

    invoke-direct {v0, p1}, Ljava/io/ByteArrayInputStream;-><init>([B)V

    invoke-direct {p0, v0}, Lnet/oauth/signature/pem/PEMReader;-><init>(Ljava/io/InputStream;)V

    .line 67
    return-void
.end method

.method private readBytes(Ljava/io/BufferedReader;Ljava/lang/String;)[B
    .locals 4
    .parameter "reader"
    .parameter "endMarker"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 119
    const/4 v1, 0x0

    .line 120
    .local v1, line:Ljava/lang/String;
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    .line 122
    .local v0, buf:Ljava/lang/StringBuffer;
    :goto_0
    invoke-virtual {p1}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;

    move-result-object v1

    if-eqz v1, :cond_1

    .line 124
    invoke-virtual {v1, p2}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I

    move-result v2

    const/4 v3, -0x1

    if-eq v2, v3, :cond_0

    .line 126
    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lnet/oauth/signature/OAuthSignatureMethod;->decodeBase64(Ljava/lang/String;)[B

    move-result-object v2

    return-object v2

    .line 129
    :cond_0
    invoke-virtual {v1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v0, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    goto :goto_0

    .line 132
    :cond_1
    new-instance v2, Ljava/io/IOException;

    const-string v3, "Invalid PEM file: No end marker"

    invoke-direct {v2, v3}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v2
.end method


# virtual methods
.method public getBeginMarker()Ljava/lang/String;
    .locals 1

    .prologue
    .line 78
    iget-object v0, p0, Lnet/oauth/signature/pem/PEMReader;->beginMarker:Ljava/lang/String;

    return-object v0
.end method

.method public getDerBytes()[B
    .locals 1

    .prologue
    .line 74
    iget-object v0, p0, Lnet/oauth/signature/pem/PEMReader;->derBytes:[B

    return-object v0
.end method

.method protected readFile()V
    .locals 6
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 90
    new-instance v2, Ljava/io/BufferedReader;

    new-instance v3, Ljava/io/InputStreamReader;

    iget-object v4, p0, Lnet/oauth/signature/pem/PEMReader;->stream:Ljava/io/InputStream;

    invoke-direct {v3, v4}, Ljava/io/InputStreamReader;-><init>(Ljava/io/InputStream;)V

    invoke-direct {v2, v3}, Ljava/io/BufferedReader;-><init>(Ljava/io/Reader;)V

    .line 93
    .local v2, reader:Ljava/io/BufferedReader;
    :cond_0
    :try_start_0
    invoke-virtual {v2}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;

    move-result-object v1

    .local v1, line:Ljava/lang/String;
    if-eqz v1, :cond_1

    .line 95
    const-string v3, "-----BEGIN "

    invoke-virtual {v1, v3}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I

    move-result v3

    const/4 v4, -0x1

    if-eq v3, v4, :cond_0

    .line 97
    invoke-virtual {v1}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v3

    iput-object v3, p0, Lnet/oauth/signature/pem/PEMReader;->beginMarker:Ljava/lang/String;

    .line 98
    iget-object v3, p0, Lnet/oauth/signature/pem/PEMReader;->beginMarker:Ljava/lang/String;

    const-string v4, "BEGIN"

    const-string v5, "END"

    invoke-virtual {v3, v4, v5}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

    move-result-object v0

    .line 99
    .local v0, endMarker:Ljava/lang/String;
    invoke-direct {p0, v2, v0}, Lnet/oauth/signature/pem/PEMReader;->readBytes(Ljava/io/BufferedReader;Ljava/lang/String;)[B

    move-result-object v3

    iput-object v3, p0, Lnet/oauth/signature/pem/PEMReader;->derBytes:[B
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 105
    invoke-virtual {v2}, Ljava/io/BufferedReader;->close()V

    return-void

    .line 103
    .end local v0           #endMarker:Ljava/lang/String;
    :cond_1
    :try_start_1
    new-instance v3, Ljava/io/IOException;

    const-string v4, "Invalid PEM file: no begin marker"

    invoke-direct {v3, v4}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v3
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 105
    .end local v1           #line:Ljava/lang/String;
    :catchall_0
    move-exception v3

    invoke-virtual {v2}, Ljava/io/BufferedReader;->close()V

    throw v3
.end method
